package com.zrentech.order.data.dbhelper.builder;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.database.Cursor;

import com.zrentech.order.data.busibean.FoodImageBean;
import com.zrentech.order.data.dbhelper.DatabaseBuilder;

/**
 * 
 * 提供关于菜谱图片的创建和解析方面的功能
 * 
 * @author Leon
 */

public class FoodImageDBuilder extends DatabaseBuilder<FoodImageBean> {

	public static final String TRACK_ID = "id";
	public static final String TRACK_FOODID = "foodID";
	public static final String TRACK_NAME = "name";
	public static final String TRACK_IMAGEPATH = "imagePath";

	@Override
	public FoodImageBean build(Cursor query) {
		int columnId = query.getColumnIndex(TRACK_ID);
		int columnFoodID = query.getColumnIndex(TRACK_FOODID);
		int columnName = query.getColumnIndex(TRACK_NAME);
		int columnImagePath = query.getColumnIndex(TRACK_IMAGEPATH);

		FoodImageBean foodimage = new FoodImageBean();
		foodimage.setId(query.getInt(columnId));
		foodimage.setFoodID(query.getInt(columnFoodID));
		foodimage.setName(query.getString(columnName));
		foodimage.setImagePath(query.getString(columnImagePath));
		return foodimage;
	}

	public List<FoodImageBean> buildMore(Cursor query) {
		List<FoodImageBean> images = new ArrayList<FoodImageBean>();
		FoodImageBean image = null;
		if(query.moveToFirst()) {
			for(int i=0; i<query.getCount(); i++) {
				query.move(i);
				int columnId = query.getColumnIndex(TRACK_ID);
				int columnFoodID = query.getColumnIndex(TRACK_FOODID);
				int columnName = query.getColumnIndex(TRACK_NAME);
				int columnImagePath = query.getColumnIndex(TRACK_IMAGEPATH);

				image = new FoodImageBean();
				image.setId(query.getInt(columnId));
				image.setFoodID(query.getInt(columnFoodID));
				image.setName(query.getString(columnName));
				image.setImagePath(query.getString(columnImagePath));
				images.add(image);
			}
		}
		return images;
	}
	
	@Override
	public ContentValues deconstruct(FoodImageBean track) {
		ContentValues values = new ContentValues();
		values.put(TRACK_ID, track.getId());
		values.put(TRACK_FOODID, track.getFoodID());
		values.put(TRACK_NAME, track.getName());
		values.put(TRACK_IMAGEPATH, track.getImagePath());
		return values;
	}

}
